import { Component } from 'react';
import { getCurrentInstance } from '@tarojs/taro';
import { View } from '@tarojs/components'
import { getTurntable } from '@/api/luck'

import './index.scss'
interface State {
  activityId: number | string
  rule: string
}

export default class Index extends Component {
  $instance = getCurrentInstance();

  constructor(props) {
    super(props)
    this.state = {
      activityId: '',//活动id
      rule: '',//活动规则
    }
  }

  state: State

  UNSAFE_componentWillMount() { }
  componentDidMount() {
    // 获取活动id
    const { activityId } = this.$instance.router.params
    this.setState({
      activityId
    }, () => {
      // 获取抽奖详情
      this.getTurntable()
    })
  }
  UNSAFE_componentWillReceiveProps(nextProps, nextContext) { }
  componentWillUnmount() { }
  componentDidShow() { }

  // 获取抽奖详情
  async getTurntable() {
    const { activityId } = this.state
    await getTurntable({ activityId }).then((res) => {
      const { data: { data } } = res
      this.setState({
        rule: data.rule
      })
    })
  }

  render() {
    const { rule } = this.state;
    return (
      <View className="body" >
        <View className="main">{rule}</View>
      </View>
    )
  }
}
